/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.scs.view;

import com.wisnu.scs.controller.DbBarangKeluarController;
import com.wisnu.scs.dao.DbBarangDao;
import com.wisnu.scs.dao.DbBarangKeluarDao;
import com.wisnu.scs.dao.DbBarangMasukDao;
import com.wisnu.scs.entity.DbBarang;
import com.wisnu.scs.entity.DbBarangKeluar;
import com.wisnu.scs.error.ErrorMessage;
import com.wisnu.scs.event.DbBarangKeluarListener;
import com.wisnu.scs.model.DbBarangKeluarModel;
import com.wisnu.scs.model.tableModel.DbBarangKeluarTableModel;
import com.wisnu.scs.model.tableModel.DbBarangMasukTableModel;
import com.wisnu.scs.util.HibernateUtil;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Wisnu Wardoyo
 */
public class DbBarangKeluarView extends javax.swing.JPanel implements DbBarangKeluarListener, ListSelectionListener {

    private DbBarangKeluarTableModel tableModel;
    private DbBarangKeluarModel model;
    private DbBarangKeluarController controller;
    private DbBarang dbBarang;
    private DbBarangKeluar dbBarangKeluar;
    private List<DbBarang> listDbBarang;

    public DbBarangKeluarView() {
        tableModel = new DbBarangKeluarTableModel();

        model = new DbBarangKeluarModel();
        model.setListener(this);
        controller = new DbBarangKeluarController();
        controller.setModel(model);

        initComponents();

        tableBarangKeluar.getSelectionModel().addListSelectionListener(this);
        tableBarangKeluar.setModel(tableModel);

    }

    public DbBarang getBarang() {
        return dbBarang;
    }

    public DbBarangKeluar getBarangKeluar() {
        return dbBarangKeluar;
    }

    public JComboBox getComboNama() {
        return comboNama;
    }

    public JRadioButton getRadioByDate() {
        return radioByDate;
    }

    public JRadioButton getRadioByMonth() {
        return radioByMonth;
    }

    public JRadioButton getRadioByRange() {
        return radioByRange;
    }

    public JTable getTableBarangKeluar() {
        return tableBarangKeluar;
    }

    public JFormattedTextField getTxtFirstDate() {
        return txtFirstDate;
    }

    public JTextField getTxtIdPengeluaran() {
        return txtIdPengeluaran;
    }

    public JTextField getTxtJumlah() {
        return txtJumlah;
    }

    public JTextField getTxtKeperluan() {
        return txtKeperluan;
    }

    public JTextArea getTxtKeterangan() {
        return txtKeterangan;
    }

    public JFormattedTextField getTxtLastDate() {
        return txtLastDate;
    }

    public JTextField getTxtPemohon() {
        return txtPemohon;
    }

    public JTextField getTxtSearchText() {
        return txtSearchText;
    }

    public JFormattedTextField getTxtTanggalKeluar() {
        return txtTanggalKeluar;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableBarangKeluar = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        txtSearchText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        radioByDate = new javax.swing.JRadioButton();
        radioByMonth = new javax.swing.JRadioButton();
        radioByRange = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtFirstDate = new javax.swing.JFormattedTextField();
        txtLastDate = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtIdPengeluaran = new javax.swing.JTextField();
        comboNama = new javax.swing.JComboBox();
        txtTanggalKeluar = new javax.swing.JFormattedTextField();
        txtPemohon = new javax.swing.JTextField();
        txtKeperluan = new javax.swing.JTextField();
        txtJumlah = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtKeterangan = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255,255,255,20)
        );

        jPanel1.setBackground(new java.awt.Color(255,255,255,20)
        );
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabel Barang Keluar"));

        tableBarangKeluar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableBarangKeluar.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                tableBarangKeluarMouseMoved(evt);
            }
        });
        jScrollPane1.setViewportView(tableBarangKeluar);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(255,255,255,20)
        );
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Administrator Panel"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Search");

        radioByDate.setText("`By Date");
        radioByDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByDateActionPerformed(evt);
            }
        });

        radioByMonth.setText("`By Month");
        radioByMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByMonthActionPerformed(evt);
            }
        });

        radioByRange.setText("`By Date's Range");
        radioByRange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByRangeActionPerformed(evt);
            }
        });

        jButton1.setText("Search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Show All");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setText("From :");

        jLabel3.setText("To :");

        txtFirstDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtFirstDate.setEnabled(false);
        txtFirstDate.setValue(new java.util.Date());

        txtLastDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtLastDate.setEnabled(false);
        txtLastDate.setValue(new java.util.Date());

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Operasi");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Id Pengeluaran :");

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Nama Barang :");

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Tanggal Keluar :");

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Pemohon :");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Keperluan :");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Jumlah :");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Keterangan :");

        txtIdPengeluaran.setEditable(false);

        comboNama.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pilih Jenis Barang" }));
        comboNama.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboNamaActionPerformed(evt);
            }
        });

        txtTanggalKeluar.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtTanggalKeluar.setValue(new java.util.Date());

        txtKeterangan.setColumns(20);
        txtKeterangan.setRows(5);
        jScrollPane2.setViewportView(txtKeterangan);

        jButton3.setText("Tambah");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Ubah");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Reset");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Hapus");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Print");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSearchText)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtIdPengeluaran))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboNama, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtTanggalKeluar)
                            .addComponent(txtPemohon)
                            .addComponent(txtKeperluan)
                            .addComponent(txtJumlah)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(radioByMonth)
                            .addComponent(jLabel1)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txtFirstDate, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                                    .addComponent(txtLastDate)))
                            .addComponent(jLabel4)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(radioByDate, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(radioByRange)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtSearchText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFirstDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtLastDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioByDate)
                    .addComponent(radioByRange))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioByMonth)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton7))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtIdPengeluaran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(comboNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtTanggalKeluar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtPemohon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtKeperluan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        controller.insertPengeluaran(this);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        controller.updatePengeluaran(this);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        controller.deletePengeluaran(this);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        controller.resetForm();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void comboNamaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboNamaActionPerformed
        if (comboNama.getItemCount() != 0 && comboNama.getSelectedIndex() != 0) {
            String[] array = comboNama.getSelectedItem().toString().split("-");
            for (DbBarang barang : listDbBarang) {
                if (barang.getIdBarang() == Integer.parseInt(array[0])) {
                    this.dbBarang = barang;
                    break;
                }
            }
        }
    }//GEN-LAST:event_comboNamaActionPerformed

    private void radioByDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByDateActionPerformed
        if (radioByDate.isSelected()) {
            radioByDate.setSelected(true);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(false);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByDateActionPerformed

    private void radioByMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByMonthActionPerformed
        if (radioByMonth.isSelected()) {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(true);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(false);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByMonthActionPerformed

    private void radioByRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByRangeActionPerformed
        if (radioByRange.isSelected()) {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(true);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(true);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByRangeActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        controller.searchPengeluaran(this);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
         try {
            loadTable();
            loadDatabase();
        } catch (ErrorMessage ex) {

        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        controller.print(this);
    }//GEN-LAST:event_jButton7ActionPerformed

    private void tableBarangKeluarMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableBarangKeluarMouseMoved
        
    }//GEN-LAST:event_tableBarangKeluarMouseMoved


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboNama;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton radioByDate;
    private javax.swing.JRadioButton radioByMonth;
    private javax.swing.JRadioButton radioByRange;
    private javax.swing.JTable tableBarangKeluar;
    private javax.swing.JFormattedTextField txtFirstDate;
    private javax.swing.JTextField txtIdPengeluaran;
    private javax.swing.JTextField txtJumlah;
    private javax.swing.JTextField txtKeperluan;
    private javax.swing.JTextArea txtKeterangan;
    private javax.swing.JFormattedTextField txtLastDate;
    private javax.swing.JTextField txtPemohon;
    private javax.swing.JTextField txtSearchText;
    private javax.swing.JFormattedTextField txtTanggalKeluar;
    // End of variables declaration//GEN-END:variables

    public void loadDatabase() throws ErrorMessage {
        DbBarangDao barangDao = HibernateUtil.getBarangDao();

        this.listDbBarang = barangDao.selectAllBarang();
        comboNama.removeAllItems();
        comboNama.addItem("Pilih Nama Barang");
        for (DbBarang barang : listDbBarang) {
            comboNama.addItem(barang.getIdBarang() + "-" + barang.getNamaBarang());
        }
        try {
            dbBarang = listDbBarang.get(0);
        } catch (IndexOutOfBoundsException exception) {
        }
        repaint();
    }

    public void loadTable() throws ErrorMessage {
        DbBarangKeluarDao barangKeluarDao = HibernateUtil.getBarangKeluarDao();
        tableModel = new DbBarangKeluarTableModel();
        tableModel.setList(barangKeluarDao.selectAllBarangKeluar());
        tableBarangKeluar.setModel(tableModel);
        repaint();
    }

    @Override
    public void onReset(DbBarangKeluarModel model) {
        txtIdPengeluaran.setText(model.getIdKeluar() + "");
        txtJumlah.setText(model.getJumlah() + "");
        txtKeperluan.setText(model.getKeperluan());
        txtKeterangan.setText(model.getKeterangan());
        txtPemohon.setText(model.getPemohon());
        //txtSearchText.setText(model.getSearchText());
        txtTanggalKeluar.setValue(model.getTanggalKeluar());
        txtSearchText.setText(model.getSearchText());
    }

    @Override
    public void onInsert(DbBarangKeluar barangKeluar) {
        tableModel.add(barangKeluar);
    }

    @Override
    public void onUpdate(DbBarangKeluar barangKeluar) {
        int index = tableBarangKeluar.getSelectedRow();
        tableModel.set(index, barangKeluar);
    }

    @Override
    public void onDelete(DbBarangKeluar barangKeluar) {
        int index = tableBarangKeluar.getSelectedRow();
        tableModel.remove(index);
    }

    @Override
    public void onSearch(List<DbBarangKeluar> listBarangKeluar) {
        tableModel = new DbBarangKeluarTableModel();
        tableModel.setList(listBarangKeluar);
        tableBarangKeluar.setModel(tableModel);
        repaint();
    }

    @Override
    public void valueChanged(ListSelectionEvent lse) {
        try {
            this.dbBarangKeluar = tableModel.get(tableBarangKeluar.getSelectedRow());
            txtIdPengeluaran.setText(dbBarangKeluar.getIdKeluar() + "");
            txtTanggalKeluar.setValue(dbBarangKeluar.getTanggalKeluar());
            txtPemohon.setText(dbBarangKeluar.getPemohon());
            txtKeperluan.setText(dbBarangKeluar.getKeperluan() + "");
            txtJumlah.setText(dbBarangKeluar.getJumlah() + "");
            txtKeterangan.setText(dbBarangKeluar.getKeterangan());

            dbBarang = dbBarangKeluar.getDbBarang();

            comboNama.setSelectedItem(dbBarang.getIdBarang() + "-" + dbBarang.getNamaBarang());

        } catch (IndexOutOfBoundsException exception) {

        }
    }
}
